package com.erp.commands.groupuser
{
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.erp.business.groupuser.GroupDelegate;
	import com.erp.commands.BaseCommand;
	import com.erp.control.BaseEvent;
	import com.erp.model.groupuser.GroupUserModelLocator;
	import com.erp.vo.ErpbaseGroup;

	import mx.collections.ArrayCollection;
	import mx.controls.Alert;

	public class GroupCommand extends BaseCommand
	{

		private var command:String;

		public function GroupCommand()
		{
		}

		override public function execute(event:CairngormEvent):void
		{
			super.execute(event);

			var baseEvent:BaseEvent=BaseEvent(event);

			command=baseEvent.type;

			var delegate:GroupDelegate=new GroupDelegate(this);

			if (command == BaseEvent.GROUP_ADD)
			{
				var group:ErpbaseGroup=baseEvent.data;
				delegate.addGroup(group);
			}
			else if (command == BaseEvent.GROUP_USER_TREE)
			{
				delegate.getUserArray();
			}

		}

		override public function result(event:Object):void
		{
		
			Alert.show(event.toString());
			super.result(event);

			if (command == BaseEvent.GROUP_ADD)
			{
				var loginFlg:Boolean=event.result as Boolean;
			}
			else if (command == BaseEvent.GROUP_USER_TREE)
			{
				var aaa:Array=event.result as Array;
				var model:GroupUserModelLocator=GroupUserModelLocator.getInstance();
				model.groupUserTree=new ArrayCollection(aaa);
			}

		}

		override public function fault(event:Object):void
		{
			super.fault(event);
			Alert.show("group error");
		}
	}
}